package br.com.condominio.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class ConverteResidencial implements Converter {

    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String str) {
        String stringObject = new String();

        if (!str.equals("")) {
            str = str.replace(".", "");
            str = str.replace("-", "");
            str = str.replace("/", "");
            stringObject = str;
        }
        return stringObject;
    }

    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object obj) {
        String stringFormatada = "";
        if (obj != null) {
            String stringValue = (String) obj;
            if (stringValue.length() == 11) {               
            	stringFormatada = FormatarCampos.formatarCpf(stringValue);                
            }            
        }
        return stringFormatada;
    }
}